package com.kaifamiao.month04.day26.work;


import java.io.File;
import java.util.*;

public class Test01 {

    // 统计某文件夹的大小
    public static void main(String[] args) {
        File file = new File("E:\\git\\read");
        File[] files = file.listFiles();
        System.out.println(getLength(files) / 1024D / 1024);
    }

    public static long getLength(File[] files) {

        ArrayList<File> fileList = new ArrayList<>(Arrays.asList(files));
        long result = 0;
        for (int i = 0; i < fileList.size(); i++) {
            File f = fileList.get(i);
            if (!f.isFile()) {
                File[] fs = f.listFiles();
                if(fs != null) {
                    fileList.addAll(Arrays.asList(fs));
                }
            } else if (f.isFile()) {
                result += f.length();
            }
        }
        return result;
    }
}
